class AddFgzyData < ActiveRecord::Migration
  def change
  	add_fgzy_and_their_parties('./data/10名分管专员姓名及所管分会.txt')
  end

  def add_fgzy_and_their_parties( file_path)
  	file= File.open( file_path)
  	file.each_line do |line|
  		name=[]
  		name= line.split("、")
  		if name
  			name= name.reverse
  			user= name.pop
  			name= name.reverse
  			u= User.new( username: user, password: "123", rule: 1, state: 0)
  			u.save
  			u= User.find_by_username( user)
  			if name
  				name.each do |n|
  					n= n.chomp+"分会"
  					puts n
  					p= Party.find_by_name(n)
  					puts p
  					binding= UserBinding.new( user_id: u.id, party_id: p.id)
  					binding.save
  				end
  			end

  		end
  	end
  end
end
